package com.soujiayi.adapter;

import java.util.List;

import com.soujiayi.activity.R;
import com.soujiayi.model.Mall;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ProductParityListAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<Mall> data;
	private String productGotoCheck = "";
	private String price_unit = "";

	public ProductParityListAdapter(Context context,
			List<Mall> data) {
		this.data = data;
		this.mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.productGotoCheck = context.getResources().getString(R.string.product_detail_goto_check);
		this.price_unit = context.getResources().getString(R.string.price_unit);
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		
		View view = convertView;
		ViewHolder holder; 
		if(view == null){
			view = mInflater.inflate(R.layout.product_parity_list_item, null);
			holder = new ViewHolder();
			holder.productMall = (TextView)view.findViewById(R.id.prodcut_paritylist_mall_item);
			holder.productPrice = (TextView)view.findViewById(R.id.prodcut_paritylist_price_item);
			holder.productGotoCheck = (TextView)view.findViewById(R.id.prodcut_paritylist_goto_check_item);
			view.setTag(holder);
		}else{
			holder = (ViewHolder)view.getTag(); 
		}
		Mall item = data.get(position);
		bindView(holder, item);

		return view;
	}

	private void bindView(ViewHolder holder, Mall item) {
		String productMall = item.getMallname();
		holder.productMall.setText(productMall.toString());
		float productPrice = item.getPrice();
		holder.productPrice.setText(String.valueOf(productPrice) + this.price_unit);
		holder.productGotoCheck.setText(productGotoCheck);
	}

	static class ViewHolder {
		TextView productMall, productPrice, productGotoCheck;
	}
	
}
